package com.edu.order.service.impl;

import com.alibaba.fastjson.JSON;
import com.edu.api.entity.common.JwtUtil;
import com.edu.order.config.RabbitmqConfig;
import com.edu.order.service.WeChatPayRabbitmq;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * @description: 描述
 * @author: xnylh
 * @createDate: 2023/3/14 0014 12:36
 */
@Service
public class WeChatPayRabbitmqImpl implements WeChatPayRabbitmq {
    @Autowired
    RabbitTemplate rabbitTemplate;


    @Override
    public void getStateOfPayment(String url, String xml, String productId, String courseName, HttpServletRequest request) {
        HashMap<String, String> map = new HashMap<>();
        map.put("url",url);
        map.put("xml",xml);
        map.put("productId",productId);
        map.put("courseName",courseName);
        map.put("userId", JwtUtil.getMemberIdByJwtToken(request));
        map.put("ip", request.getRemoteAddr());
        rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_DIRECT_INFORM,RabbitmqConfig.ROUTINGKEY_PAYMENT_SUCCESS, JSON.toJSONString(map));
    }
}
